package com.bestv.search.common.dao.hibernate;

import com.bestv.search.common.dao.ScheduleDao;
import com.bestv.search.common.model.Schedule;

import java.util.Date;
import java.util.List;

public class ScheduleDaoHibernate extends GenericDaoHibernate<Schedule, Long> implements ScheduleDao {

    public ScheduleDaoHibernate() {
        super(Schedule.class);
    }

    @Override
    public void saveScheduleList(List<Schedule> list) {
        super.saveObjectList(list);
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<Schedule> getSchedulesByCode(String code) {
        return getHibernateTemplate().find("from Schedule s where s.code = ?", code);
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<Schedule> getExpiredSchedules() {
        Date now = new Date();
        return getHibernateTemplate().find("from Schedule s where s.updateFlag != 2 and s.expireTime <= ?", now);
    }
}
